package utils;

import DataStructure.linkList.ListNode;

public class CommonUtils {

    public static void swap(int[] A, int i, int j) {
        int temp = A[i];
        A[i] = A[j];
        A[j] = temp;
    }

    public static int[] getRandomNums(int len, int maxNum) {
        if (len < 1) {
            len = 1;
        }
        int[] arr = new int[len];
        for (int index = 0; index < len; index++) {
            arr[index] = (int) (Math.random() * maxNum);
        }

        return arr;
    }

    public static ListNode makeNodeList(int[] nums) {
        if (nums == null || nums.length == 0)
            return null;
        ListNode head = new ListNode(nums[0]);
        ListNode p = head;
        for (int i=1;i < nums.length;i++) {
            p.next = new ListNode(nums[i]);
            p = p.next;
        }
        return head;
    }
}
